var ns, toast,Dialog;
var app = new Vue({
    el: '#app',
    data: {
        OrderID: 0,
        show:false,
        showsend:false,//发货弹窗
        form:{}, //订单状态：1-待付款 5-待发货 2-已发货 3-已完成 4-已取消
    },
    methods: {
        get_data: function() {
            var that = this;
            var option={
                  action: 'getorderdetail',
                  OrderID: that.OrderID,
            };
            ns.post(option, function(succeed, data, err) {
                // console.log(JSON.stringify(err));
                // console.log(JSON.stringify(data));
                if (succeed) {
                    if(data.status){
                        that.form = data.data;
                        if (that.form.AppointmentTime && that.form.AppointmentEndTime) {
                            var moment1 = moment(new Date(that.form.AppointmentTime), 'MM/D/YYYY');
                            var moment2 = moment(new Date(that.form.AppointmentEndTime), 'MM/D/YYYY');
                            var IsSameDay = moment1.isSame(moment2, 'day');
                            if (IsSameDay) {
                                that.form.AppointmentEndTime = ns.DateFormatYY(that.form.AppointmentEndTime);
                            }
                        }
                    }
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        //打开物流信息
        do_openStep:function(){
            var that = this;
            ns.openWin('logistics_frm', '订单跟踪',{
                id:that.OrderID,
                AddressDetailInfo:that.form.AddressDetailInfo,
            });
        },
        tel_phone: function (telPhone) {
            if (!telPhone || telPhone == undefined) {
                api.toast({
                    msg: '电话号码为空',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            api.call({
                type: 'tel_prompt',
                number: telPhone
            });
        },
        //取消订单
        do_removeorder:function(){
            var that=this;
            that.show=true;
        },
        //取消订单
        beforeClose:function(action,done){
            var that=this;
            if(action==='confirm'){
                var option={};
                option.OrderID=that.OrderID;
                option.action='cancelorder';
                ns.post(option, function(succeed, data, err) {
                    if(succeed){
                        if(data.status){
                            api.toast({
                                msg: '操作成功',
                                duration: 2000,
                                location: 'bottom'
                            });
                            that.get_data();
                            api.sendEvent({
                                name:'relod_orderlist'
                            });
                        }
                    }else{
                        api.toast({
                            msg: err,
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                });
                that.show=false;
                done();
            }else if(action==='cancel'){
                done();
            }
        },
         //删除订单
         do_deleteorder: function () {
            var that = this;
            api.confirm({
                title: '提示',
                msg: '确定删除?',
                buttons: ['确定', '取消']
            }, function (ret, err) {
                if (ret.buttonIndex == 1) {
                    //调用删除接口
                    var opt = {
                        action: 'deleteorder', //删除的方法名
                        OrderID: that.OrderID,
                    };
                    ns.post(opt, function (succeed, data, err) {
                        if (succeed) {
                            api.toast({
                                msg: '操作成功！',
                                duration: 2000,
                                location: 'bottom'
                            });

                            //刷新并关闭
                            setTimeout(() => {
                                api.sendEvent({
                                    name: 'relod_orderlist',
                                });
                                api.closeWin();
                            }, 1000);

                        } else if (err) {
                            api.toast({
                                msg: err,
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                    })
                }
            });
        },
        //复制订单编号
        copy_txt:function(){
            var test=document.getElementById("dindan");
            test.select(); 
            document.execCommand("copy"); // 执行复制命令
            api.toast({
                msg: '复制成功',
                duration: 2000,
                location: 'bottom'
            });
        },
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    toast = new auiToast();
    app.OrderID = api.pageParam.id;
    app.get_data();
    
};
